﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TTBusiness.DB_Linq;
using TTBusiness.ClassDB;
using TTBusiness;
namespace TTMarketing.Admin
{
    public partial class Order : System.Web.UI.Page
    {
        clsBSOrder objDB = new clsBSOrder();
        protected void Page_Load(object sender, EventArgs e)
        {
            divmessage.InnerHtml = "";
            divmessage2.InnerHtml = "";
        }

        protected void cmbClose_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (Convert.ToInt32(e.Value) == 1)
            {
                plDetail.Visible = true;
            }
            else
            {
                plDetail.Visible = false;
            }
        }

        protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(rgdGrid.Items[rgdGrid.SelectedIndexes[0]]["ID"].Text);
                tblOrder mfc = new tblOrder();
                mfc = objDB.getById(id);
                this.plDetail.Visible = true;
                this.lblAddress.Text = mfc.Address;
                this.lblDate.Text = mfc.Date.Value.ToLongDateString();
                this.lblDetail.Text = mfc.Detail;
                this.lblEmail.Text = mfc.Email;
                this.lblFullName.Text = mfc.FullName;
                this.lblPhone.Text = mfc.Phone;
                this.hfId.Value = id.ToString();
                this.cmbClose.SelectedValue = "1";
                this.rgdGrid2.Rebind();
            }
            catch (Exception ex)
            {
                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi : " + ex.Message).ToString();
            }
        }


        protected void rgdGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("delete"))
                {
                    objDB.delete(Convert.ToInt32(e.CommandArgument));
                    divmessage2.InnerHtml = clsBSMessageAdmin.MessageSuccess("Thành công : ", "Đã xóa thành công!").ToString();
                    this.rgdGrid.Rebind();
                    
                }
            }
            catch (Exception)
            {
                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi không thể xóa được").ToString();
            }
        }
    }
}